<div class="well clearfix">

<?php
$this->load->helper('date');
$cd_user ='';
foreach ($query->result() as $row)
{
	$cd_user = $row->cd_user;
	$date = timespan(time(), human_to_unix(($row->dt_end).' 00:00 AM'));
	$name_user = $row->fl_identification=='1'?$row->nm_user:'Anonimous';
	echo '<h2>'.$row->nm_project.' <small>('.lang("word_by").' '. $name_user .')</small></h2>';
	echo '<strong class="pull-right alert alert-error" style="margin-top:-55px"><i class="icon-calendar"></i> '.lang("word_remaining").': '. $date .'</strong>';
	echo '<strong class="pull-right alert alert-info" style="margin-top:-55px"><i class="icon-gift"></i> '.lang("active_projects_premium").': R$'.$row->vl_value.'</strong>';
	echo '<h4>'.lang("word_segment").': '.$row->nm_style.'</h4>';
	echo '<h4>'.lang("word_description").'</h4>';
	echo '<blockquote>'.$row->ds_description.'</blockquote>';	
}
if ($cd_user != $this->session->userdata('id')){ 
?>
<button class="btn btn-primary clearfix" href="#myModal" data-toggle="modal"><?=lang('btn_send_a_job')?></button>
<hr>
<h3>Seus trabalhos enviados:</h3>
<?php 
	$this->db->from('jobs');
	$this->db->where('jobs.cd_designer', $this->session->userdata('id'));
	$this->db->where('jobs.cd_project', $id_project);
	$query = $this->db->get();
	echo '<ul class="thumbnails">';
	foreach ($query->result() as $row)
	{
		$thumb = '<li class="col-md-4"><div class="thumbnail">';
		$thumb .= '<img style="margin-bottom:5px" src="'.base_url().$row->nm_urlimage.'"/>';

		$thumb .= '<a class="btn btn-mini" href="#myModalMessage" data-job="'.$row->id_job.'" onclick="setJob(this)" data-toggle="modal" role="button"><i class="icon icon-envelope"></i> '.lang("btn_view_send_message").'</a>';
		$thumb .= '<div class="star" data-score="'.$row->vl_stars.'" data-job="'.$row->id_job.'" style="float:right"></div>';
		$thumb .= '</div></li>';		
		echo $thumb;
	}
	echo '</ul>';
?>
<?php $this->load->view('form/send_a_job'); ?>
<?php

}else{ 
?>   
<h3><?=lang('title_jobs_sended')?>:</h3>
<?php
	$this->db->from('jobs');
	$this->db->where('jobs.cd_project', $id_project);
	$query = $this->db->get();
	echo '<ul class="thumbnails">';
	foreach ($query->result() as $row)
	{
		$thumb = '<li class="col-md-4"><div class="thumbnail">';
		$thumb .= '<img style="margin-bottom:5px" src="'.base_url().$row->nm_urlimage.'"/>';
		
		$thumb .= '<a class="btn btn-mini" href="#myModalMessage" data-job="'.$row->id_job.'" onclick="openMessages(this)" data-toggle="modal" role="button"><i class="icon icon-envelope"></i> Ver/enviar mensagem</a>';
		$thumb .= '<div class="star" data-score="'.$row->vl_stars.'" data-job="'.$row->id_job.'" style="float:right; width:100px"></div>';
		$thumb .= '</div></li>';
		echo $thumb;
	}
	echo '</ul>';
} 

?>
<?php $this->load->view('form/send_message'); ?>
</div>
<script type="text/javascript">
var jobSelected;
$('.star').raty({ 
	path: '<?=base_url();?>assets/img/raty', 
	width: false,
	<?php if ($cd_user != $this->session->userdata('id')){ ?>
	readOnly: true,
	<?php } ?>
	hints: <?=lang('rating_hits') ?>,
	score: function() {
		return $(this).attr('data-score');
	},
	click: function(){
		alert($(this).raty('score'));
		$.ajax({
	        url : '<?=base_url(); ?>'+'project/rate/'+$(this).attr('data-job')+'/'+$(this).raty('score'),
	        success : function(data){
	        	alert('sucesso com score: '+ data[rate]);
	        	
	        }
		});
	}
});
var job = '';
function openMessages(obj){
	job = $(obj).attr('data-job');
	$.ajax({
        url : '<?=base_url(); ?>'+'project/get_messages/'+job,
        success : function(data){
        	$("#messages").html(data);
        	setTimeout(function() {
        	      $('.modal-body').animate({scrollTop:$('#messages').height()}, 'slow');
        	}, 1000);
        	
        }
	});
}

function sendMessage(){
	$.ajax({
        url : '<?=base_url(); ?>'+'project/send_message/'+job,
        type : 'POST', 
        data : {'message' : $('#message-field').val()},
        success : function(data){
        	$("#messages").html(data);
        	$('#message-field').val('');
        	$('.modal-body').animate({scrollTop:$('#messages').height()}, 'slow');   	
        }
	});
}
</script>